<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

</body>
<script>
  Array.prototype.groupBy = function (fn) {
    const res = {}
    for (const item of this) {
      const key = fn(item);
      if (!res.hasOwnProperty(key)) res[key] = [];
      res[key].push(item)
    }
    return res
  };
  array = [
    { "id": "1" },
    { "id": "1" },
    { "id": "2" }
  ],
    fn = function (item) {
      return item.id;
    }
  console.log(array.groupBy(fn));
</script>

</html>